package com.tanhua.server.controller;

import com.tanhua.domain.vo.ContactVo;
import com.tanhua.domain.vo.PageResult;
import com.tanhua.server.service.IMService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 消息相关的操作
 */
@RestController
@RequestMapping("/messages")
public class IMController {

    @Autowired
    private IMService imService;

    /**
     * 点击聊一聊后添加好友
     *
     * @param paramMap
     * @return
     */
    @PostMapping("/contacts")
    public ResponseEntity makeFriends(@RequestBody Map<String, Long> paramMap) {
        imService.makeFriends(paramMap.get("userId"));
        return ResponseEntity.ok(null);
    }

    /**
     * 联系人列表
     * @param page
     * @param pageSize
     * @param keyword
     * @return
     */
    @GetMapping("/contacts")
    public ResponseEntity queryContactsList(@RequestParam (value = "page",defaultValue = "1") Long page,
                                            @RequestParam (value = "pagesize",defaultValue = "10") Long pageSize,
                                            String keyword){
        PageResult<ContactVo> pageResult = imService.queryContactsList(page,pageSize,keyword);
        return ResponseEntity.ok(pageResult);
    }
}
